package com.example.framework.mvp.mvp.view

import android.widget.Toast
import com.cmy.framework_base.basics.BasicsFragment
import com.cmy.framework_base.common.loading.SimpleLoadDialogImp
import com.cmy.framework_utils.toast.toast
import com.example.framework.mvp.mvp.presenter.BasePresenter

/**
 * @name:
 *  BaseFrafment
 * @package:
 *  com.example.framework.mvp.mvp.view
 * @date:
 *  2023/2/1714:34
 * @author
 *    cmy
 * @description
 *
 */
abstract class BaseFragment <V : BaseView?, P : BasePresenter<V>?>  : BasicsFragment() ,BaseView{

    @JvmField
    protected var mPresenter: P? = null

    /**
     * 创建当前页面presenter
     *
     * @return 当前页面关联的presenter
     */
    protected abstract fun createPresenter(): P?


    override fun setWindowConfigure() {
        super.setWindowConfigure()

        //TODO 暂时不实用弹窗显示，因为Ui反倒变得不好看，没有好的反馈意
//        registerLoadDialogView(SimpleLoadDialogImp(childFragmentManager))
        mPresenter = createPresenter()
        mPresenter?.attachView(this as V)
    }


    override fun showToast(msg: String) {
        msg.toast(requireActivity(), Toast.LENGTH_SHORT)
    }

    override fun onDestroyView() {
        mPresenter?.detachView()
        super.onDestroyView()
    }

}